package com.sansui.blog.controller.admin.page;

import com.sansui.blog.pojo.SysConfig;
import com.sansui.blog.pojo.sys.SysEmail;
import com.sansui.blog.service.SysEmailService;
import com.sansui.blog.service.SysInfoService;
import com.sansui.blog.service.impl.SysEmailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @name: SysSettingController
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-11-25 09:29
 **/

// 系统管理 - 发信邮箱设置
@Controller
@RequestMapping("/admin")
public class SysEmailController {

    @Autowired
    private SysEmailService sysEmailService;

    //  系统后台-系统设置
    @GetMapping("page/email")
    public ModelAndView adminEmail(ModelAndView mv){

        try{
            SysEmail sysEmail = sysEmailService.getSysEmail();
            mv.addObject("mailCloud",sysEmail.getMailCloud());
            mv.addObject("mailSmtp",sysEmail.getMailSmtp());
            mv.addObject("mailPort",sysEmail.getMailPort());
            mv.addObject("mailUser",sysEmail.getMailUser());
            mv.addObject("mailName",sysEmail.getMailName());
            mv.addObject("mailPwd",sysEmail.getMailPwd());
            mv.addObject("status",sysEmail.getStatus());
            mv.setViewName("admin/page/email");
        }catch (Exception e){
//            e.printStackTrace();
        }
        return mv;
    }

    @PostMapping("page/saveEmail")
    @ResponseBody
    public Map<String, Object> saveEmail(@RequestBody SysEmail sysEmail){
        Map<String, Object> map = sysEmailService.saveEmail(sysEmail);
        return map;
    }

    @PostMapping("page/setEmailDemo")
    @ResponseBody
    public Map<String, Object> setEmailDemo(String demoMail){
        Map<String, Object> map = sysEmailService.setEmailDemo(demoMail);
        return map;
    }


//    @PostMapping("page/updateSendEmailStatus")
//    @ResponseBody
//    public Map<String, Object> updateSendEmailStatus(String status){
//        System.out.println(status);
////        Map<String, Object> map = sysEmailService.setEmailDemo(demoMail);
//        return null;
//    }

}
